import { IPostAge } from "./interface";
import * as service from "../../service";
const postAge: IPostAge = {
  namespaced: true,
  state: {
    niceLists: [],
    goodLists: [],
    navs: [],
  },
  actions: {
    async getNiceLists({ commit }) {
      const result = await service.fecthNiceLists();
      const action = {
        type: "GET_NICELISTS",
        payload: result?.data?.goodsList,
      };
      commit(action);
    },
    async getGoodLists({ commit }, { params }) {
      const result = await service.fecthGoodLists(
        params.cid,
        params.pageNo,
        params.pageSize
      );
      const action = {
        type: "GET_GOODLISTS",
        payload: result?.data?.lists,
      };
      commit(action);
    },
    async getPostAgeNav({ commit }) {
      const result = await service.fetchPostAgeNav();
      const action = {
        type: "GET_POSTAGE_NAV",
        payload: result?.data,
      };
      commit(action);
    },
    async getMoreLists({ commit }, { params }) {
      const result = await service.fecthGoodLists(
        params.cid,
        params.pageNo,
        params.pageSize
      );
      const action = {
        type: "GET_MORELISTS",
        payload: result?.data?.lists,
      };
      commit(action);
    },
  },
  mutations: {
    GET_NICELISTS(state, action) {
      state.niceLists = action.payload;
    },
    GET_GOODLISTS(state, action) {
      state.goodLists = action.payload;
    },
    GET_POSTAGE_NAV(state, action) {
      state.navs = action.payload;
    },
    GET_MORELISTS(state, action) {
      state.goodLists.push(...action.payload);
    },
  },
};

export default postAge;
